﻿//===========================[ 7 / 6 / 2011 LVI ]=============================
//				Copyright c Vitaly Lyaschenko <SkyChameleon@gmail.com>
//								Source file
// Purpose: 
//=============================================================================
#include "cTimer.h"
#include <Windows.h>

LARGE_INTEGER   startTime,      // начальное время
                currentTime,    // текущее время
                lastTime,		// старое значение счетчика
                frequency;	    // тиков за секунду
float time,
      frameTime,
      multiplier = 1;

//cTimer::cTimer()
//{
//	lastTime.QuadPart = startTime.QuadPart = frequency.QuadPart = 0;
//}

void cTimer::init()
{
    QueryPerformanceFrequency(&frequency);
    QueryPerformanceCounter(&startTime);
    lastTime = startTime;
}

void cTimer::update()
{
    QueryPerformanceCounter(&currentTime);

    frameTime = multiplier * (float)(currentTime.QuadPart - lastTime.QuadPart) / frequency.QuadPart;

    time +=frameTime;

    lastTime = currentTime;
}

float cTimer::getTime()
{
    return time;
}

float cTimer::getFrameTime()
{
    return frameTime;
}

_64ubit cTimer::getCurrentTime()
{
    QueryPerformanceCounter(&currentTime);
    return currentTime.QuadPart;
}

void cTimer::setMultiplier( float mult )
{
    multiplier = mult;
}

float cTimer::getMultiplier()
{
    return multiplier;
}
